package main.剑指OfferⅠ;

public class Day4 {
    public static void main(String[] args) {
        System.out.println("剑指Offer03.数组中重复的数字");
        System.out.println("剑指Offer53-Ⅰ.在排序数组中查找数字 I");
        System.out.println("剑指Offer53-Ⅱ.0~n-1中缺失的数字");
    }
}

class Offer03{
    public int findRepeatNumber(int[] nums) {
        int result=-1,length=nums.length;
        int[] count=new int[length];
        for (int num:nums){
            count[num]++;
            if (count[num]>1){
                result=num;
                break;
            }
        }
        return result;
    }
}

class Offer53_Ⅰ{
    public int search(int[] nums, int target) {//进阶二分
        int count=0;
        for (int num:nums){
            if (target==num) count++;
        }
        return count;
    }
}

class Offer53_Ⅱ{
    public int missingNumber(int[] nums) {//进阶二分
        int left=0,right=nums.length-1;
        while (left<=right){
            int mid=left+(right-left)/2;
            if (nums[mid]>mid) right=mid-1;
            else left=mid+1;
        }
        return left;
    }
}